#include "Object.h"

NS_B2D_BEGIN

ObjectType::ObjectType(void)
	: mBaseType(nullptr)
	, mTypeId(TypeToId<Object>::Id())
{
}

ObjectType::ObjectType(const ObjectType& t)
	: mBaseType(t.mBaseType)
	, mTypeId(t.mTypeId)
{
}

ObjectType& ObjectType::operator = (const ObjectType& t)
{
	mBaseType = t.mBaseType;
	mTypeId = t.mTypeId;
	return *this;
}

bool ObjectType::isOfType(const ObjectType& t) const
{
	return t == *this;
}

bool ObjectType::derivesFromType(const ObjectType& t) const
{
	// Iterate the type hierarchy until the end or
	// until the type is found
	const ObjectType* myType = this;
	while(myType != nullptr)
	{
		if(t == *myType) return true;
		myType = myType->mBaseType;
	}
	return false;
}

const ObjectType Object::Type = ObjectType();

NS_B2D_END